
#include "ascendancy.h"



GLfloat		x1 = 0.0f;
GLfloat		y1 = 0.0f;
GLfloat		rectSize = 25;

GLfloat		xstep = 1.0f;
GLfloat		ystep = 1.0f;

GLfloat		windowWidth;
GLfloat		windowHeight;

Galaxy		*galaxy;
RenderGalaxy	*galaxyRender;
RenderMenu	*menuRender;


static int	currentView;

int		main(int argc, char **argv)
{
  init();
  glutInit(&argc, argv);
  glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_ALPHA | GLUT_DEPTH);

//   glutInitWindowSize(800, 600);
//   glutCreateWindow("Ascendancy");

    glutGameModeString("1280x1024:32@60");
    glutEnterGameMode();

  glutReshapeFunc(changeSize);

  // input events
  glutKeyboardFunc(normalKeys);
  glutSpecialFunc(specialKeys);
  glutMouseFunc(mouseEvent);
  glutPassiveMotionFunc(mousePassiveMotion);


  glutDisplayFunc(RenderScene);
  setupRc();

  glutMainLoop();

  return(0);
}

void		init()
{
  // create our galaxy
  galaxy = new(Galaxy);
  galaxy->generate();
  // create the associated renderer
  galaxyRender = new(RenderGalaxy);
  galaxyRender->init(galaxy);

  menuRender = new(RenderMenu);
  menuRender->init();

  currentView = GALAXY_VIEW;
//   currentView = MENU_VIEW;
}

void		normalKeys(unsigned char key, int x, int y)
{
  switch(currentView)
    {
    case GALAXY_VIEW:
      galaxyRender->normalKeyEvent(key, x, y);
      break;
    case MENU_VIEW:
      menuRender->normalKeyEvent(key, x, y);
      break;
    }
}

void		specialKeys(int key, int x, int y)
{
  switch(currentView)
    {
    case GALAXY_VIEW:
      galaxyRender->specialKeyEvent(key, x, y);
      break;
    case MENU_VIEW:
      menuRender->specialKeyEvent(key, x, y);
      break;
    }
}

void		mouseEvent(int button, int state, int x, int y)
{
  switch(currentView)
    {
    case GALAXY_VIEW:
      galaxyRender->mouseEvent(button, state, x, y);
      break;
    case MENU_VIEW:
      menuRender->mouseEvent(button, state, x, y);
      break;
    }
}

void		mousePassiveMotion(int x, int y)
{
  switch(currentView)
    {
    case GALAXY_VIEW:
      galaxyRender->mousePassiveMotion(x, y);
      break;
    case MENU_VIEW:
      menuRender->mousePassiveMotion(x, y);
      break;
    }
}

void		RenderScene(void)
{
  switch(currentView)
    {
    case GALAXY_VIEW:
      galaxyRender->render();
      break;
    case MENU_VIEW:
      menuRender->render();
      break;
    }
}

void		setupRc(void)
{
  switch(currentView)
    {
    case GALAXY_VIEW:
      galaxyRender->setupRc();
      break;
    case MENU_VIEW:
      menuRender->setupRc();
      break;
    }
}

void		changeSize(GLsizei w, GLsizei h)
{
  switch(currentView)
    {
    case GALAXY_VIEW:
      galaxyRender->changeSize(w, h);
      break;
    case MENU_VIEW:
      menuRender->changeSize(w, h);
      break;
    }
}

